﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using DevExpress.Xpo;
using Zero.Core.Domain;
using Zero.Core.Domain.Query;
using Zero.DataLayer.Donnees;
using Zero.POCO.Compagne;

namespace Zero.DataLayer.Repository
{//juste un test
    public class CampagneRepository : IRepository<Compaign, Guid>
    {
        public Compaign FindBy(Guid id)
        {
            throw new NotImplementedException();
        }

        public IEnumerable<Compaign> FindAll()
        {
            var listCompaigns=new List<Compaign>();

            var config = new AppSettingsReader();
            using (
               var uow = new UnitOfWork()
               {
                   ConnectionString =
                       ((string)config.GetValue("connect", typeof(string)))
               })
            {
                var compaigns = new XPCollection<XpoCompaign>(uow);
                listCompaigns.AddRange(compaigns.Select(MAP.MapInverse.MapCampaign));
            }
            return listCompaigns;
        }

        public IEnumerable<Compaign> FindBy(Query query)
        {
            throw new NotImplementedException();
        }

        public IEnumerable<Compaign> FindBy(Query query, int index, int count)
        {
            throw new NotImplementedException();
        }

        public void SaveAll(IEnumerable<Compaign> entities)
        {
            throw new NotImplementedException();
        }

        public List<Compaign> FindAll(List<Query> entities)
        {
            throw new NotImplementedException();
        }

        public void Save(Compaign entity)
        {

            var config = new AppSettingsReader();
            using (
                   var uow = new UnitOfWork()
                   {
                       ConnectionString =
                           ((string)config.GetValue("connect", typeof(string)))
                   })
            {
                var comp = MAP.Map.MapCompaign(entity, uow);
                uow.CommitChanges();
            }
        }

        public void Add(Compaign entity)
        {
            throw new NotImplementedException();
        }

        public void Remove(Compaign entity)
        {
            throw new NotImplementedException();
        }
    }
}
